﻿using AutoMapper;
using B.S.DataBase.SuY.Wirt.Api.AutoList.Command;
using B.S.DataBase.SuYuan.Domain.Model;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructrue.Interface;
using MediatR;
using System.Collections.Generic;

namespace B.S.DataBase.SuY.Wirt.Api.AutoList.CommandHarder
{
    public class ShowCommodityCommandHarder : IRequestHandler<ShowCommodityCommand, ApiReslit<List<Commodity>>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRepository<Commodity> repository;

        public ShowCommodityCommandHarder(IMapper mapper, IBaseRepository<Commodity> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public Task<ApiReslit<List<Commodity>>> Handle(ShowCommodityCommand request, CancellationToken cancellationToken)
        {
            ApiReslit<List<Commodity>> result = new ApiReslit<List<Commodity>>();
            result.Code= ApiEnum.查询成功;
            result.Msg = ApiEnum.查询成功.ToString();
            var list = repository.GetAll().Result;
            result.data= list.ToList();
            return  Task.FromResult(result);
        }
    }
}
